package cn.whpu.controller;

import cn.whpu.domain.Account;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
@RequestMapping("/account")
public class AccountController {
    /**
     * 查询账户
     * @param accountId
     * @param accountName
     * @return
     */
    @RequestMapping("/findAccount")
    public String findAccount(Integer accountId,String accountName){
        System.out.println("查询了账户id。。。"+accountId);
        System.out.println("查询了账户名。。。"+accountName);
        return "success";
    }

    /**
     * 保存账户
     * @param account
     * @return
     */
    @RequestMapping("/saveAccount")
    public String saveAccount(Account account){
        System.out.println("保存了账户"+account);
        return "success";
    }

    /**
     * 根据时间删除账户
     * @param date
     * @return
     */
    @RequestMapping("/deleteAccount")
    public String deleteAccount(Date date){
        System.out.println("删除了账户"+date);
        return "success";
    }
    @RequestMapping("/testServletAPI")
    public String testServletAPI(HttpServletRequest request, HttpServletResponse response, HttpSession session){
        System.out.println(request);
        System.out.println(response);
        System.out.println(session);
//        System.out.println(session.getServletContext());
        return "success";
    }

    @RequestMapping("/usePathVariable/{id}")
    public String usePathVariable(@PathVariable("id") Integer accountId){
        System.out.println("id = "+accountId);
        return "success";
    }

    @RequestMapping("/useCookieValue")
    public String useCookieValue(@CookieValue("JSESSIONID") String cookieValue){
        System.out.println(cookieValue);
        return "success";
    }

}
